import { defineStore } from "pinia";
import { ref } from "vue";

let nearbyList = ref([])
const useCartStore = defineStore('carts', () => {

  const change=(id,list)=>{
    let index = nearbyList.value.findIndex(function(item) {
        return item == id
      });
      if (index==-1&&list.length) {
        console.log(1);
          nearbyList.value.push(list)
    }else{
      console.log(2);
    }
  }
  return { nearbyList,change }
})

export default useCartStore


// let numbers = [1, 12, 5, 18, 8];
 
// let index = numbers.findIndex(function(item) {
//   return item > 10;
// });
 
// if (index !== -1) {
//   numbers.splice(index, 1, numbers[index] * 2); // 找到后将元素乘以2并替换
// }
 
// console.log(numbers); // 输出: [1, 24, 5, 18, 8]